#include "TimeoutErr.h"

#include <stdarg.h>
#include <string.h>
#include <fan-llvm/core/Core.h>
#include "Str.h"
#include "Type.h"


Type* TimeoutErr_classType = NULL;
VTable* TimeoutErr_classVTable = NULL;


/**********************************************
 *
 * Methods and fields
 *
 **********************************************/


/* Void make(Str msg, Err? cause) */
void TimeoutErr_make_0(TimeoutErr* self)
{
  TimeoutErr_make(self, Str_defVal(), NULL);
}


/* Void make(Str msg, Err? cause) */
void TimeoutErr_make_1(TimeoutErr* self, Str* msg)
{
  TimeoutErr_make(self, msg, NULL);
}


/* Void make(Str msg, Err? cause) */
void TimeoutErr_make(TimeoutErr* self, Str* msg, Err* cause)
{
  Err_make((Err*)self, msg, cause);
}


/**********************************************
 *
 * Extra methods
 *
 **********************************************/


/* Create a new TimeoutErr instance and initialize it with TimeoutErr_make() */
TimeoutErr* TimeoutErr_new(Str* msg, Err* cause)
{
  TimeoutErr* err = (TimeoutErr*)Obj_allocate(sizeof(TimeoutErr), TimeoutErr_classVTable);
  TimeoutErr_make(err, msg, cause);
  return err;
}


/* Create a new TimeoutErr instance and initialize it with the message given by the specified format.
 * 'msgFormat' uses the same format as Str_newWithFormat() */
TimeoutErr* TimeoutErr_newWithFormattedMsg(const char* msgFormat, ...)
{
  va_list args;
  va_start(args, msgFormat);
  Str* msg = Str_newWithFormatValist(msgFormat, args);
  va_end(args);
  return TimeoutErr_new(msg, NULL);
}


/**********************************************
 *
 * Type-system functions
 *
 **********************************************/


Type* TimeoutErr_initType(void)
{
  if (TimeoutErr_classType == NULL)
  {
    Type* baseType = Err_initType();
    VTable* vtable = TimeoutErr_initVTable();
    Type* type = Type_new("TimeoutErr", baseType, vtable, sizeof(TimeoutErr), sizeof(TimeoutErrVTable));
    Type_registerCtorImplementation(type, "make", TimeoutErr_make_0, 0);
    Type_registerCtorImplementation(type, "make", TimeoutErr_make_1, 1);
    Type_registerCtorImplementation(type, "make", TimeoutErr_make, 2);
    TimeoutErr_classType = type;
    TimeoutErr_initStatic();
  }
  return TimeoutErr_classType;
}


VTable* TimeoutErr_initVTable(void)
{
  if (TimeoutErr_classVTable == NULL)
  {
    VTable* vtable = memoryAlloc(sizeof(TimeoutErrVTable));
    memcpy(vtable, Err_initVTable(), sizeof(ErrVTable));
    TimeoutErr_classVTable = vtable;
  }
  return TimeoutErr_classVTable;
}


void TimeoutErr_initStatic(void)
{
}
